package cn.yunhe.actions;

import cn.yunhe.model.Type;
import cn.yunhe.service.TypeBiz;
import cn.yunhe.util.BaseActionUtil;
import cn.yunhe.util.ModelDisplayUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/*spring注解*/
@Controller(value = "typeAction")
@Scope(value = "prototype")
/*struts2注解*/
/*@ParentPackage(value = "struts-default")*/
@ParentPackage(value = "json-default")
public class TypeAction extends BaseActionUtil {
    List<Type>typeList=new ArrayList<>();

    /*spring注解*/
    @Autowired
    @Qualifier("typeBiz")
    TypeBiz typeBiz;

    /*struts2注解*/
    @Action(value = "type_searchType1",results = {
            @Result(name = "success",location = "/searchType.jsp"),
            @Result(name = "error",location = "/fail2SearchType.jsp"),
    })
    public String searchType(){
        //此处的Type1对应
        //@Entity(name = "Type1")
        //@Table(name = "type")
        List<Type>typeList=typeBiz.searchType("from Type1");
        getRequest().setAttribute("typeList1",typeList);

        ModelDisplayUtil.listType(typeList);
        return SUCCESS;
    }

    @Action(value = "type_searchType",results = {
            @Result(name = "success",location = "/searchType.jsp"),
            @Result(name = "error",location = "/fail2SearchType.jsp"),
            @Result(name = "typeList1",type = "json",params = {"root","typeList"}),
    })
    public String searchType1(){
        //此处的Type1对应
        //@Entity(name = "Type1")
        //@Table(name = "type")
        typeList=typeBiz.searchType("from Type1 ");
        //getRequest().setAttribute("typeList1",typeList);

        ModelDisplayUtil.listType(typeList);
        return "typeList1";
    }

    public TypeBiz getTypeBiz() {
        return typeBiz;
    }

    public void setTypeBiz(TypeBiz typeBiz) {
        this.typeBiz = typeBiz;
    }

    public List<Type> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<Type> typeList) {
        this.typeList = typeList;
    }
}
